package com.smg.community.util;

import java.util.Calendar;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javacommon.util.FileUtil;

public class ProjectUtil {

	
	public static String imageUploadPath = "";
	
	public static String imagePrefix = "";
	
	private static Properties p ;
	
	static 
	{
		 p = FileUtil.loadProperties("config.properties");
		 imageUploadPath = p.getProperty("imageUploadPath");
		 imagePrefix = p.getProperty("imagePrefix");
	}
	/**
	 * 获取登录的用户名的类型
	 * @param loginName  
	 * 账号类型:
		1:昵称（原为卡账号）
		2:手机号
		3:邮箱
		4:卡号
	 * @return
	 */
	public static int getLoginNameType(String loginName){
	if ( StringUtil.isEmpty(loginName))
		return 0;
	if ( isMobileNO(loginName)){
		return Constant.LOGIN_TAGRT_MOBILE;
	}else if  ( isEmail(loginName)){
		return Constant.LOGIN_TAGRT_EMAIL;
	}
	return 1;
}	
		
	/**
	 *  获取用户注册输入的登录名类型  1 - 手机  2 - 邮箱
	 * @param userName
	 * @return
	 */
	public static int getRegTargetType(String loginName){
		if ( StringUtil.isEmpty(loginName))
			return 0;
		if ( isMobileNO(loginName)){
			return Constant.REG_TAGRT_MOBILE;
		}else if  ( isEmail(loginName)){
			return Constant.REG_TAGRT_EMAIL;
		}
		return 0;
	}
	 public static boolean isMobileNO(String mobiles){     
	        Pattern p = Pattern.compile("^\\d{11}$");     
	        Matcher m = p.matcher(mobiles);     
	        return m.matches();     
	  } 
	 public static boolean isEmail(String email){     
	     String str="^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$";
	        Pattern p = Pattern.compile(str);     
	        Matcher m = p.matcher(email);     
	        return m.matches();     
	    } 
	 public static final String[] zodiacArr = { "猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊" };   
	  
	 public static final String[] constellationArr = { "水瓶座", "双鱼座", "牡羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座",   
	         "天蝎座", "射手座", "魔羯座" };   
	   
	 public static final int[] constellationEdgeDay = { 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22 };   
	   
	 /**  
	  * 根据日期获取生肖  
	  * @return  
	  */  
	 public static String date2Zodica(Calendar time) {   
	     return zodiacArr[time.get(Calendar.YEAR) % 12];   
	 }   
	   
	 /**  
	  * 根据日期获取星座  
	  * @param time  
	  * @return  
	  */  
	 public static String date2Constellation(int month,int day) {   
		 if ( month == 0 )
			 month = 1;
		 month = month -1 ;
	     if (day < constellationEdgeDay[month]) {   
	         month = month - 1;   
	     }   
	     if (month >= 0) {   
	         return constellationArr[month];   
	     }   
	     //default to return 魔羯   
	     return constellationArr[11];   
	 }  
	 
	 public static void main(String[] args){
		    Calendar time = Calendar.getInstance();
	       int month = time.get(Calendar.MONTH);
	        int day = time.get(Calendar.DAY_OF_MONTH);
	        System.out.println(month);
	        System.out.println(day);
	 }
}
